<?php
include_once 'conf/DbUserPages.php';

class userConnector extends DBUserPages{
	/*****
	 * Datenbank aktuelle connect
	 *****/
	protected $Con;

	/*****
	 * Letzte Sql-Anweissung
	 *****/
	private $sql;

	/*****
	 * Das letzte Ergebniss
	 *****/
	protected $result;

	public $error = false;
	public $insert_id = null;
	public $errno = null;

	#Der Konstruktor
	function __construct() {
		try{
			$this->connect();
		}catch (Exception $e){
			$e->getMessage();
		}
	}

	#Das Connection auf die Datenbank
	function connect() {
		$this->Con = mysql_connect ( $this->DbServer,$this->DbUser, $this->DbPassword);
		if (mysql_error ())
		throw new Exception ( "Error Code 1: Ups beim Verbinden mit der Datenbank () ist ein fehler unterlaufen" );

		$this->setDbTabele ();
	}
	public static function StartUserConnector() {
		return new userConnector();
	}
	#Datenbank Tabele Ausw�hlen
	function setDbTabele() {
		$this->Con = mysql_select_db ($this->DbTabele, $this->Con );
	}

	#Select Anweisung wird ausgef�hrt
	function Select($sql) {
		$this->sql = $sql;
		$this->result = mysql_query($sql);
		
		if(mysql_error()){
			$this->error = mysql_error();
			$this->errno = mysql_errno();
			$this->error_sql = $sql;
		}
		$this->insert_id = mysql_insert_id();
	}

	public function __sleep() {
		return array ('server', 'username', 'password', 'db' );
	}

	public function __wakeup() {
		$this->connect ();
	}

	function affectedrows() {
		return (@mysql_affected_rows ( $this->Con ));
	}

	function numrows() {
		return (@mysql_num_rows ( $this->result ));
	}

	function fetchobject() {
		$final = array();

		while ( false != ($lauf = mysql_fetch_object($this->result))) {
			array_push($final,$lauf);
		}
		
		return $final;
	}

	function fetcharray() {
		return (mysql_fetch_array ( $this->result ));
	}

	function fetchassoc() {
		$final = array();

		while ( false !== ($lauf = mysql_fetch_assoc ( $this->result ))) {
			array_push($final,$lauf);
		}
		return $final;
	}

}

?>